package flowchart.app;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 *
 * @author sh
 */
public class Exiter extends WindowAdapter {

    private DiagramView view;

    public Exiter(DiagramView dv) {
        view = dv;
    }

    public void windowClosing(WindowEvent e) {

        if (!view.saved()) {
            int result = view.showUnsavedConfirm();
            if (result == 0) {
                if (view.saveFile()) {
                    System.exit(0);
                }

            } else if (result == 1) {
                System.exit(0);
            }
        } else {
            System.exit(0);
        }

    }
}
